load("data/cleaned/lasso_control.RData", verbose = TRUE)

lasso_controls

control_vars_with_names %>% enframe() %>%
  select(name) %>%
  kable(linesep = "", booktabs = TRUE, format = "latex", col.names = c("Variable")) %>%
  kable_styling() %>%
  kable_remove_table() %>%
  write_lines("outputs/tables/possible_controls.tex")

lasso_export <- lasso_controls %>%
  bind_rows(.id = "table") %>%
  select(table, column, name) %>%
  mutate(used = "X") %>%
  complete(table, column, name) %>%
  pivot_wider(names_from = c(table, column), values_from = used)


options(knitr.kable.NA = '')


lasso_names <- names(lasso_export)
lasso_table_names <- c(rep("Effect of\n3-person\ndiscussion\n(Table 1)", 2),
rep("Effect of\nrights\nvideos\n(Table 2)", 2))
lasso_model_i <- lasso_names %>% str_split("_") %>% .[2:length(.)] %>% map_chr(2) %>% paste0("(", ., ")")

lasso_header <- vec_to_custom_header(lasso_table_names)

lasso_export %>%
  kable(linesep = "", booktabs = TRUE, format = "latex", 
        col.names = c("Variable", lasso_model_i),
        align = c('l', rep('c', 4))) %>%
  kable_styling() %>%
  kableExtra::column_spec(column = 2:10, width = rep("0.5in", 9)) %>%
  kableExtra::add_header_above(c(" " = 1, lasso_header)) %>%
  kable_remove_table() %>%
  write_lines("outputs/tables/lasso_controls.tex")
